let express = require('express');
let router = express.Router();

const fileService = require('../service/fileService');

// 引入jwt验证方法的中间件
const checkJWTMiddleWare = require('../middleWare/checkJWTMiddleWare');
router.use(checkJWTMiddleWare);

router.post('/downloadPublicFile', async function(req, res, next) {
    let uid = req.jwtResult.data.uid;
    let fileId = req.body.fileId;
    if (!fileId) {
        res.status(400).json({ success: false, message: 'fileId 不能为空' });
    }
    let result = await fileService.downloadPublicFile(fileId, uid);
    res.status(result.success ? 200 : 400).json(result);
});

module.exports = router;